package com.ziJing.multithreading.sync;

import java.util.concurrent.BrokenBarrierException;
import java.util.concurrent.CyclicBarrier;

/**
 * @program Multithreading
 * @description:
 * @author: zhangbo
 * @create: 2022/05/03 14:42
 */
public class T05_TestCyclicBarrier {


    public static void main(String[] args) throws InterruptedException {
        CyclicBarrier barrier = new CyclicBarrier(20, () -> System.out.println("满人，发车！"));


        Thread[] threads = new Thread[100];
        for (int i = 0; i < threads.length; i++) {
            threads[i] = new Thread(() -> {
                try {
                    barrier.await();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                } catch (BrokenBarrierException e) {
                    e.printStackTrace();
                }
            });
        }


        for (int i = 0; i < threads.length; i++) {
            threads[i].start();
        }
    }




}
